package com.example.seleniumtest;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class example {
    public static void main(String[] args) throws InterruptedException {
        //驱动程序自动化
        WebDriverManager.chromedriver().setup();
        ChromeOptions options = new ChromeOptions();

        //允许访问所有连接
        options.addArguments("--remote-allow-origins=*");

        //设置完基础设置之后,就开始进行操作
        //1.打开对应的浏览器(首先要创建一个驱动对象)
        WebDriver webDriver = new ChromeDriver(options);
        Thread.sleep(5000);
        //2.输入对应网址,这里访问百度
        webDriver.get("https://www.baidu.com");
        Thread.sleep(5000);
        //3.找到输入框并进行搜索操作
        webDriver.findElement(By.xpath("//*[@id=\"kw\"]")).sendKeys("CSDN");
        Thread.sleep(5000);
        //4.找到搜索按钮
        webDriver.findElement(By.xpath("//*[@id=\"su\"]")).click();
        Thread.sleep(5000);
        //5.关闭浏览器
        webDriver.close();
    }
}
